/*
 * $Id: UserRole.java 12 2014-08-10 04:00:19Z ratking $
 *
 * Copyleft (C) 2014 RatKing. All wrongs reserved.
 */
package cn.ratking.demo.jaws6.model;

import java.io.Serializable;
import java.util.Objects;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

/**
 * 用户的角色
 */
@Entity
@Table(name = "T_User_Role",
        uniqueConstraints = {
            @UniqueConstraint(columnNames = {"username", "roleCode"})
        })
public class UserRole implements Serializable {

    /** 用户名 */
    @Id
    @NotNull
    @Size(min = 1, max = 20)
    private String username;
    /** 角色代码 */
    @Id
    @NotNull
    @Size(min = 1, max = 20)
    private String roleCode;

    /** 无参构造方法 */
    public UserRole() {
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getRoleCode() {
        return roleCode;
    }

    public void setRoleCode(String roleCode) {
        this.roleCode = roleCode;
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 19 * hash + Objects.hashCode(this.username);
        hash = 19 * hash + Objects.hashCode(this.roleCode);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (!(obj instanceof UserRole)) {
            return false;
        }
        final UserRole other = (UserRole) obj;
        if (!Objects.equals(this.username, other.username)) {
            return false;
        }
        if (!Objects.equals(this.roleCode, other.roleCode)) {
            return false;
        }
        return true;
    }

    /**
     * 返回测试字符串
     *
     * @return 测试字符串
     */
    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();

        sb.append("[UserRole: username=").append(username);
        sb.append(", roleCode=").append(roleCode);
        sb.append("]");

        return sb.toString();
    }
}
